home *** CD-ROM | disk | FTP | other *** search
- ---------------------------------------------------------------------------
- Welcome to the Chessboard component v1.0 for Delphi 2, Delphi 3 and
- Borland C++ Builder !
-
- version 1.11 - July 25th 1997
- ---------------------------------------------------------------------------
- Description:
-
- The Chessboard component provides a customizable 2D Chessboard
- that can keep track of a game and verify the legality of moves.
- It allows the programmer to trap the following events:
-
- LegalMove, Illegal Move, Capture, En Passant, Castling, Promotion,
- Check, Mate, Stale Mate and Only Two Kings Left.
-
- The colors, size, Pieces and Squares can be customized. The component
- can be resized at runtime.
-
- The Chessboard component comes with three files:
- Chess.cpp (source file), Chess.h (header file) and Chess.txt
- (current file).
-
- ---------------------------------------------------------------------------
- Installation of the component:
-
- Start Delphi2, Delphi3 or Borland C++ Builder.
- Select "Component", "Install" ,"Add" and
- "Browse" and then browse to the file CHESS.PAS. The component will
- appear on a new tab called Chess.
- Note: Borland C++ Builder users can also choose for CHESS.CPP
- ---------------------------------------------------------------------------
- Product History:
-
- version 1.11 - July 25th 1997
- * Small bug in PAS file did not allow compiling of the component.
- version 1.1 - July 23th 1997
- * Fixed bug: Pieces were not displayed properly when being dragged
- if the Chessboard were not the child of the form
- * Fixed bug: The letters A-H were not displayed in the right position
- if WhiteOnTop were TRUE
- * Removed property Align because it was put there without the
- intention.
- * Added property Enabled, which allows to lock the Chessboard
- * Added member function DrawChessPiece which allows displaying
- of a chess piece outside of the component.
- * Datatype Square is now being used consequently
-
- version 1.0 - June 20th 1997
- * Added PAS file for Delphi2 and Delphi3
- version 1.0 - June 11th 1997
- * initial version (C++ Builder only)
- ----------------------------------------------------------------------------
-
- Property Descriptions:
-
- Boardlines: Boolean
- Determines whether lines will be drawn
- around the board and between the squares
-
- BorderBitmap: TBitmap
- If assigned a value, this bitmap will be used to draw the border around
- the board. BorderColor will then be ignored.
-
- BorderColor: TColor
- Sets the color of the border. Will be visible only if no value has
- been assigned to BorderBitmap.
-
- CastlingAllowed: CastleSet
- This set stores whether castling is still allowed for each king in each
- direction. Example: CastleSet<<WhiteKingSide will allow short castling
- for white while CastleSet>>BlackQueenSide will disable long castling
- for Black.
-
- CoordFont: TFont
- Sets the font eventually used to display the coordinates around the board.
-
- CurrentMove: Integer
- Stores the current move of the game in the list. CurrentMove cannot be
- modified directly. Use: GotoMove (int move, bool WhiteMoves);
- to change its value.
-
- CustomPieceSet: TBitmap
- If assigned a legal value (that is a bitmap with a Width of
- 1.5 times its Height) this bitmap will be used as the new piece set
- instead of the default The bitmap should consist of 6 x 4 smaller square
- bitmaps of equal size. The order of the pieces should be: pawn, knight,
- bishop, rook, queen and king. The first row represents the white pieces,
- the third row represents the black pieces. The second and fourth row
- should be monochrome and will be used to determine the mask of the white
- and black pieces respectively. The pieces will not be shown in the place
- where the mask bitmap contains a non-zero value. This allows transparent
- drawing of the pieces on the board.
-
- DisplayCoords: CoordSet
- Determines whether coordinates are being displayed around the screen.
- Examples: DisplayCoords<<West will display coordinates on the left of
- the board. DisplayCoords>>East will make disappear coordinates at the
- right of the board.
-
- EnPassant: Square
- if EnPassant doesn't equal None, it contains the square on which
- an EnPassant capture can take place. If white moves for instance
- E2-E4, EnPassant will be set to the value E3 (on which the pawn
- can be taken). Legal values are: A3-H3, A6-H6
-
- LineStyle: TPen
- Contains the linestyle eventually used to display lines between
- the squares and around the board.
-
- Position: String
- The contents of the board are stored in this string which is
- always 64 characters long. The board is stored from square
- A8 through H8 to H1. Each character represents a piece on the
- board. The characters P, N, B, R, Q, K represent the pawn
- knight, bishop, rook, queen and king respectively.
- White pieces are uppercased, black pieces lowercased. Empty
- squares are represented by spaces.
- To quickly initialize a standard setup, fill the string
- with 'init'.
-
- Resizable: Boolean
- Determines whether the ChessBoard can be resized. If TRUE,
- when the user moves the cursor over the right-down corner,
- the shape of the cursor will change and allow the ChessBoard
- to be resized. The resizing does not yet happen flicker-free.
-
- ResizeMinSize: Integer
- The minimum allowed size of the ChessBoard (it's Width and Height)
- while it is in the resizing state.
-
- ResizeMaxSize: Integer
- The maximum allowed size of the ChessBoard (it's Width and Height)
- while it is in the resizing state.
-
- SizeOfBorder: Integer
- Determines the width of the border around the board. Changing its
- value may change the size of the chessboard as well. (Width and Height)
-
- SizeOfSquare: Integer
- Determines the squaresize. Changing its value may change the size of
- the chessboard as well. (Width and Height)
-
- SquareColorDark: TColor
- The color of the dark squares. Will be visible only if no value has
- been assigned to SquareDark.
-
- SquareColorLight: TColor
- The color of the light squares. Will be visible only if no value has
- been assigned to SquareLight.
-
- SquareDark: TBitmap
- If assigned a value, this bitmap will be used to draw the border around
- the board to display the dark squares. SquareColorDark will then be
- ignored.
-
- SquareLight: TBitmap
- If assigned a value, this bitmap will be used to display the light
- squares. SquareColorLight will then be ignored.
-
- StandardSize: StandardSet
- Sets the size of the standard pieceset. The standard pieceset will
- only be used if no value has been assigned to CustomPieceSet.
- Legal values are: size32, size40, size64 and size80
-
- WhiteOnTop: Boolean
- Controls whether the white pieces are being
- displayed on top of the board. Use: WhiteOnTop=!WhiteOnTop to flip the
- board.
-
- WhiteToMove: Boolean
- Readonly. Sets the turn to white if TRUE and to black if FALSE;
-
- ---------------------------------------------------------------------------
- Methods of the Public Interface:
-
- -Pieces can contain the following (char) values:
- p,b,n,r,q or k for a black pawn, knight bishop, rook queen or king
- P,B,N,R,Q or K for a white pawn, knight bishop, rook queen or king
-
- function BlackInCheckAfter(oldsq, newsq: Square): Boolean
- returns TRUE if black is in check after the indicated move
-
- function ClearSquare(sq: Square): Boolean
- will empty the square with number sqn
-
- function ColorOfPiece (piece: Char): Integer
- returns BLACK (0) or WHITE (1) if piece is a legal piece
- otherwise NOPIECE (-1)
-
- function ColorOfSquare (sq: Square): Integer
- returns BLACK or WHITE according to the color of square sqno.
-
- procedure DrawChessPiece (canvas: TCanvas; x,y: Integer; piece: Char)
- Draws the Chess piece, indicated by 'piece' on the given canvas,
- at the given offset (x,y).
- This method uses some kind of MaskBlt, and draws only in the place
- where the mask has its bits set so drawing on a patterned surface
- is possible.
-
- function GetMove (moveno: Integer; whiteMoves: Boolean): MoveInfo
- Returns a MoveInfo structure filled with the information
- about the indicated move. Returns a structure with all
- zero values and an initial position in the case the
- move could not be found in the movelist.
-
- function GetMoveList: TStringList
- Returns a TStringList with all the moves of the current game.
-
- function GotoMove (moveno: Integer; whiteMoves:Boolean): Boolean
- Jump to the indicated move in the game and
- set the position accordingly. Returns FALSE if
- the move cannot be found in the movelist.
-
- function LegalMoveAvailable: Boolean;
- Returns TRUE if a move can be made from the current position.
-
- function MouseToSquare (x, y: Integer): Square;
- converts coordinates to a square value.
- For instance CoordsToSquare (1,4) will return A4.
-
- function Move (oldsq, newsq: Square): Boolean
- will make a move and return TRUE if the move is legal.
- The move will be both displayed on the board and registered in
- memory. For castling: pass the move of the king.
- Example: Move (E2,E4)
-
- function MoveBackward: Boolean
- Moves backward in the list of played moves and sets the position
- accordingly. Returns FALSE if there's no move available.
-
- function MoveForward: Boolean
- Moves forward in the list of played moves and sets the position
- accordingly. Returns FALSE if there's no move available.
-
- procedure NewGame
- Resets the position to the initial state.
-
- function SetUpPosition (pos: MoveInfo; moveno: Integer; whiteMoves:Boolean): Boolean
- Sets up the ChessBoard according to a given position. The first
- move in the game will be moveno.
-
- procedure UpdateChessBoard (char *oldpos);
- Ensures all pieces are displayed on the right position.
- Can be used if you change property Position manually.
-
- function WhiteInCheckAfter(oldsq, newsq: Square):Boolean
- returns TRUE if white is in check after the indicated move
-
- function WindowToSquare (x, y: Integer): Square
- returns the square at the position of (x,y).
- x and y must be relative to the current window.
-
- function XPos (sq: Square): Integer
- returns the x-Coordinate (as an integer number in the range 1-8)
- of the square.
-
- function YPos (sq: Square): Integer
- returns the x-Coordinate (as an integer number in the range 1-8)
- of the square.
-
- ---------------------------------------------------------------------------
- Event Handlers:
-
- procedure Capture (Sender: TObject;oldSq,newSq: Square;CapturedPiece:Char)
-
- procedure Castle (Sender: TObject;oldSq,newSq: Square)
-
- procedure Check (Sender: TObject; oldSq, newSq: Square)
-
- procedure Click; override
-
- procedure DragCanceled; override;
-
- procedure DragDrop(Source: TObject;X,Y: Integer);override
-
- procedure DragOver(Source: TObject;X,Y: Integer; State: TDragState;var Accept: Boolean );override
-
- procedure EndDrag(drop:Boolean)
-
- procedure IllegalMove (Sender:TObject; sq: Square)
-
- procedure LegalMove (Sender:TObject;oldSq,newSq: Square)
-
- procedure Mate (Sender:TObject; oldSq,newSq: Square)
-
- procedure MouseDown(Button:TMouseButton; Shift:TShiftState;X,Y: Integer); override
-
- procedure MouseMove(Shift:TShiftState; X,Y: Integer); override
-
- procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer);override
-
- procedure OnlyTwoKingsLeft (Sender:TObject)
-
- procedure Paint; override
-
- procedure Promotion (Sender: TObject;oldSq,newSq: Square; var NewPiece: Char)
- Note: you can choose your piece by assigning a new value to NewPiece.
-
- procedure StaleMate (Sender: TObject; oldSq,newSq: Square)
-
- ------------------------------------------------------------------------------
- Copyright, Liability and Author:
-
- The Chessboard component may be freely used and distributed by anyone.
- The author does not accept liability for the software in any way.
-
- Note that the standard pieceset that's being used comes straight out of
- Fritz4 for I thought I would never be able to design such clear and charming
- pieces. So take care not to break any laws with copyrighted material.
- If you would like to receive some Chess pieces from some other popular
- Chess programs, just drop me a line, which you can do as well if you
- have any bug reports, comments, suggestions, or wanted features:
-
- Daniel Terhell
- Amsterdam
- Tel: +31 20 4866128
- kr8m8pr8@compuserve.com
- http://ourworld.compuserve.com/homepages/kr8m8pr8
- ------------------------------------------------------------------------------
-
-